<?php
require_once('./includes/headers.inc.php');
require_once('./top.php');

$error = FALSE;
$name = '';
$description = '';

if($_POST) {
    $location_id = $locationMgr->add($_POST);
    if($location_id) {
        $_SESSION['checkin']['location_id'] = $location_id;
        $_SESSION['msg'] = $msgMgr->get('add-location-success', array('{name}' => $_POST['name']));
        header('Location: /pickroute.php');
        exit();
    } else {
        $error = $msgMgr->get('add-location-error');
        $name = $_POST['name'];
        $description = $_POST['description'];
    }
}

$replaces = array(
    'name'          => $name,
    'description'   => $description,
    'error'         => $msgMgr->formatMsg($error),
);
$lang = array(
    'header_add_location'   => $langMgr->get('header_add_location'),
    'text_name'             => $langMgr->get('text_name'),
    'text_description'      => $langMgr->get('text_description'),
    'btn_add'               => $langMgr->get('btn_add'),
);
$templateMgr->loadContent(basename(__FILE__, '.php'), array_merge($replaces, $lang));
?>
